<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="/WEB-INF/view/admin/nav.jsp"></jsp:include>
<head>
<title>彩票系统</title>
<link href="common.css" rel="stylesheet">
<link href="layout.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="libs/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="libs/index.css">
<script src="require.js"></script>
<script src="require-config.js"></script>
<script type="text/javascript">
require([ "require-config" ], function() {
    require([ 'jquery', 'validate' ], function() {
        $('#roleSelect').on('change', function() {
            var item = $(this).children('option:selected'), itemValue = item.data("value");
            if (itemValue != 0) {
                var itemLabel = item.data("label");
                $('#role' + itemValue).remove();
                $('#roles').append('<div id="role' + itemValue + '"><i class="fa fa-minus-circle"></i> ' + itemLabel + '<input type="hidden" name="roleIds" value="' + itemValue + '" /></div>');
            }
        });
        $('#roles').delegate('.fa-minus-circle', 'click', function() {
            $(this).parent().remove();
        });

        $('form').validate({
            rules : {
                oldPassword: {
                    required: true
                },
                newPasswrod: {
                    required: true
                }
            },
            messages : {
                oldPassword: {
            		required: '旧密码不能为空'
            	},
            	newPasswrod: {
            		required: '新密码不能为空'
            	}
            },
            submitHandler : function(form) {
                $.ajax({
                    url: 'pwd',
                    type: 'POST',
                    data: {
                        'memberAccount': $('#memberAccount').val(),
                        'oldPassword': $('#oldPassword').val(),
                        'newPasswrod': $('#newPasswrod').val()
                    },
                    dataType: 'json',
                    beforeSend: function() {
                        $("#frm_submit").attr("disabled", true);
                    },
                    success: function(response) {
                        if (true == response.success) {
                        	alert(response.message);
                            window.location.href = 'list';
                        } else {
                            alert(response.message);
                        }
                        $("#frm_submit").attr("disabled", false);
                    },
                    error: function() {
                        $("#frm_submit").attr("disabled", false);
                    }
                });
            }
        });
    });
});
</script>
</head>

<!-- Content. -->
<!-- Page Content -->
<div id="page-wrapper">
	<div class="row">
		<div class="box">
			<form role="form" autocomplete="off" method="POST">
				<div class="box-body">
					<div class="form-group">
						<label>登录账号<span class="required-flag">*</span></label>
						<div class="input-group">
							<div class="input-group-addon">
								<i class="fa fa-user"></i>
							</div>
							<input name="memberAccount" type="text" class="form-control"
								id="memberAccount" placeholder="登录账号" value="${sessionScope.username}" readonly="readonly">
						</div>
						<label>请输入旧密码<span class="required-flag">*</span></label>
						<div class="input-group">
							<div class="input-group-addon">
								<i class="fa fa-user"></i>
							</div>
							<input name="oldPassword" type="password" class="form-control" id="oldPassword"
								placeholder="旧密码">
						</div>
						<label>请输入新密码<span class="required-flag">*</span></label>
						<div class="input-group">
							<div class="input-group-addon">
								<i class="fa fa-user"></i>
							</div>
							<input name="newPasswrod" type="password" class="form-control" id="newPasswrod"
								placeholder="新密码">
						</div>
					</div>
				</div>
				<div class="box-footer">
					<div class="form-group">
						<button type="submit" id="frm_submit" class="btn btn-primary">提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<jsp:include page="/bottom.jsp"></jsp:include>